#include<iostream>
#include<cstdio>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string>

const std::string myenv = "HELLO=7777777";

int main()
{
    putenv((char*)myenv.c_str());
    pid_t id = fork();
    if(id == 0)
    {
        // execl("/bin/ls", "ls", "-la", "--color", nullptr);
        // execl("/usr/bin/python", "python", "test.py", nullptr);
        char* const argv[] = {
            (char*)"other",
            nullptr
        };
        char* const env[] = {
            (char*)"HELLO=world",  // 这里加char*只是为了防止报错
            (char*)"HELLO1=world1",
            (char*)"HELLO2=world2",
            (char*)"HELLO3=world3" 
        };
        execvpe("./other", argv, environ);
        // execl("./other", "other", nullptr);
        exit(1);
    }
    pid_t rid = waitpid(id, nullptr, 0);
    if(rid > 0)
    {
        printf("等待子进程成功\n");
        execl("./other", "other", nullptr);
    }
    return 0;
}
